package org.anderground.editor.gui.properties.line;

import java.util.List;
import java.util.Observable;
import java.util.Set;

import org.anderground.core.model.Line;
import org.anderground.core.model.Station;
import org.anderground.core.model.Tunnel;
import org.anderground.editor.gui.properties.AbstractPropertiesPanel;
import org.anderground.editor.model.EditorModel;

@SuppressWarnings("serial")
public class LinePropertiesPanel extends AbstractPropertiesPanel<Line> {

	private Line[] lines;

	public LinePropertiesPanel() {
		super(new LineNameProperty(), new LineTrainDelayProperty(),
				new LineColorProperty());
	}

	@Override
	public void onSelectionChanged(List<Station> selectedStations,
			List<Tunnel> selectedTunnel) {

	}

	@Override
	public void update(Observable arg0, Object arg1) {
		Set<Line> linesSet = EditorModel.getInstance().getData().getLines();
		this.lines = (Line[]) linesSet.toArray(new Line[linesSet.size()]);
		super.update(arg0, arg1);
	}

	@Override
	protected int getRowCount() {
		return (lines == null) ? 0 : lines.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return (lines == null || rowIndex < 0 || rowIndex >= lines.length) ? null
				: lines[rowIndex];
	}

}
